﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using System.IO;
using System.Xml;

namespace Reborn_WorldServer.App1AppHandler
{
    public class TradeTrainerData
    {
        private string trainerType;
        private bool canLearn = false;
        private bool canUnlearn = false;

        private CreatureBase trainer;
        private string message = "";

        private decimal currentLevel;

        public TradeTrainerData (Character character, CreatureBase creature, string trainerType)
        {
            this.trainerType = trainerType;
            this.trainer = creature;

            currentLevel = character.skillManager.GetCurrentLevel(trainerType);

            if (character.recipieManager.hasSkill(trainerType) == true)
            {
                canLearn = false;
                canUnlearn = true;
            }
            else if (character.recipieManager.canLearn(out message) == true)
                canLearn = true;
        }
        public string toXML()
        {
            string result = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("TradeTrainerData");

            xmldoc.WriteAttributeString("TrainerName", trainer.Name.ToString());
            xmldoc.WriteAttributeString("TrainerCreatureID", trainer.CreatureID.ToString());
            xmldoc.WriteAttributeString("TrainsSkill", trainerType);
            xmldoc.WriteAttributeString("canLearn", canLearn.ToString());
            xmldoc.WriteAttributeString("canUnlearn", canUnlearn.ToString());
            xmldoc.WriteAttributeString("currentLevel", currentLevel.ToString());
            xmldoc.WriteAttributeString("message", message.ToString());

            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }
}
